package com.rimi.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.rimi.bean.User;
import com.rimi.cache.SelectCache;
import com.rimi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user3")
public class User3Controller {

    @Autowired
    private UserService userService;

    @Autowired
    private SelectCache selectCache;

    @RequestMapping("/in")
    public String in(Model model, HttpServletRequest request, HttpSession session, HttpServletResponse response
    ,String isok , String email , String sex, String text_like , String text_info ){
        System.out.println("hehe--------------------");
        User user = (User) session.getAttribute("user");
        if(email==null && sex==null && text_like==null && text_info==null){

        }else if(email==user.getUserEmail() && sex==user.getUserSex() && text_like==user.getUserLike() && text_info==user.getUserInfo()){

        } else {
            User user1 = new User();
            user1.setUserEmail(email);
            user1.setUserSex(sex);
            user1.setUserInfo(text_info);
            user1.setUserLike(text_like);
            userService.update(user1,new EntityWrapper<User>().eq("user_id",user.getUserId()));
            user = userService.selectOne(new EntityWrapper<User>().eq("user_id", user.getUserId()));
            selectCache.removeCacheList("user"+user.getUserName());
            selectCache.removeCacheList("user"+user.getUserPhone());
            session.setAttribute("user",user);
        }
        if (user!=null) {
            model.addAttribute("user1",user);
        }else {
            return "/login";
        }
        return "personal_center";
    }



}
